package com.cskaoyan.gateway.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mall.user.intercepter.TokenIntercepter;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: GetUidUtil
 * @Author: WangEnzhao
 * @Description: 获取用户id工具
 * @CreateTime: 2021/12/22:49:00
 */
public class GetUidUtil {

    public static Long getUid(HttpServletRequest servletRequest){
        String userInfo = (String) servletRequest.getAttribute(TokenIntercepter.USER_INFO_KEY);
        JSONObject object = JSON.parseObject(userInfo);
        long uid = Long.parseLong(object.get("uid").toString());

        return uid;
    }

}
